project(ascendcl_c_utest)
if(ENABLE_OPEN_SRC)
    find_package(c_base CONFIG REQUIRED)
endif()

set(CMAKE_CXX_STANDARD 11)
if (ENABLE_OPEN_SRC)
    find_package(c_base CONFIG REQUIRED)
endif()

set(UT_FILES
    "main.cpp"
    "acl_unittest.cpp"
    "acl_rt_unittest.cpp"
    "acl_slogtest.cpp"
    "model_unittest.cpp"
    "acl_mdlDesc_test.cpp"
    "enum_check.cpp"
)

set(UT_STUBS
    "${CMAKE_CURRENT_SOURCE_DIR}/stub/runtime_stub.cpp"
)

set(SRC_FILES
    "${BASE_DIR}/c/runtime/callback.c"
    "${BASE_DIR}/c/runtime/host_func.c"
    "${BASE_DIR}/c/runtime/context.c"
    "${BASE_DIR}/c/runtime/device.c"
    "${BASE_DIR}/c/runtime/stream.c"
    "${BASE_DIR}/c/common/acl.c"
    "${BASE_DIR}/c/runtime/memory.c"
    "${BASE_DIR}/c/model/model_config.c"
    "${BASE_DIR}/c/model/model_exec_config.c"
    "${BASE_DIR}/c/model/model.c"
    "${BASE_DIR}/c/model/model_desc.c"
    "${BASE_DIR}/c/types/tensor_desc_internal.c"
    "${BASE_DIR}/tests/ut/acl/testcase_c/gmock_executor/ge_executor_stub.cc"
    "${BASE_DIR}/tests/ut/acl/testcase_c/stub/acl_ge_stub.cpp"
)

############ ascendcl_c_utest ############
add_executable(ascendcl_c_utest
               ${UT_FILES}
               ${SRC_FILES}
               ${UT_STUBS}
)

#include directories
target_include_directories(ascendcl_c_utest PRIVATE
    if (NOT ENABLE_OPEN_SRC)
        ${TOP_DIR}/inc
        ${TOP_DIR}/inc/external
    else()
        $<$<BOOL:${ENABLE_OPEN_SRC}>:${ASCEND_OPENSDK_DIR}/include/>
        $<$<BOOL:${ENABLE_OPEN_SRC}>:${ASCEND_OPENSDK_DIR}/include/air>
        $<$<BOOL:${ENABLE_OPEN_SRC}>:${ASCEND_OPENSDK_DIR}/include/runtime>
        $<$<BOOL:${ENABLE_OPEN_SRC}>:${ASCEND_OPENSDK_DIR}/include/msprof>
        $<$<BOOL:${ENABLE_OPEN_SRC}>:${ASCEND_OPENSDK_DIR}/include/slog>
    endif()
        ${BASE_DIR}/inc/external
        ${BASE_DIR}/c/
        ${BASE_DIR}/c/common
        ${BASE_DIR}/c/model
        ${BASE_DIR}/tests/ut/acl/testcase_c/
        ${BASE_DIR}/tests/depends/
        ${BASE_DIR}/inc/external/acl
        ${BASE_DIR}/tests/depends/
        ${BASE_DIR}/tests/ut
)

target_compile_options(ascendcl_c_utest PRIVATE
    -fsanitize=address -fsanitize=leak
    -g --coverage -fprofile-arcs -ftest-coverage
    -Wall -Wextra -Wfloat-equal -Werror
)

target_compile_definitions(ascendcl_c_utest PRIVATE
    google=ascend_private
    ENABLE_DVPP_INTERFACE
    RUN_TEST
    $<$<STREQUAL:${ENABLE_OPEN_SRC},True>:ONLY_COMPILE_OPEN_SRC>
)

target_link_libraries(ascendcl_c_utest PRIVATE
    -fsanitize=address -fsanitize=leak
    $<BUILD_INTERFACE:intf_pub>
    c_base_static
    c_base_headers
    c_sec
    gtest
    gtest_main
    gmock
    gmock_main
    slog
    -lrt
    -ldl
    -lpthread
    -lgcov
)